package controllers;

import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import messages.*;
import ocsf.server.ConnectionToClient;
import messages.ComplaintMessage;

public class DBController {

	public DBController(Object msg, ConnectionToClient client)  throws SQLException, IOException{
			
			  String[] strMsg;
			  
			  msg= msg.toString().substring(1, msg.toString().length()-1); // remove the [] from the msg by substring 
			  strMsg = msg.toString().split("[ , ] "); // remove the , from msg and splitting it to tiny str array parts  
			  
			  System.out.println(strMsg[0]);
			  System.out.println(strMsg[1]);             
			  System.out.println(strMsg[2]);

			  
			  switch(strMsg[0]){
			  
			  case("Login"): {
				  LoginMessage loginMsg= new LoginMessage(strMsg, client);
				  loginMsg.activation();
				  break;
			  }
			  
			  case("Complaint"): {
				  ComplaintMessage complaintMsg=new ComplaintMessage(strMsg,client);
				  complaintMsg.activation();
				  break;
			  }
			  
			  case("Logout"): {
				  LogoutMessage logoutMsg=new LogoutMessage(strMsg,client);
				  logoutMsg.activate(strMsg[1]);
				  break;
			  }
			  
			  
			  }
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
	}

	
	
}
